/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ua.lviv.franko.visualisation;

import java.awt.Color;
import java.awt.Graphics;
import java.util.List;

import javax.swing.JPanel;

import ua.lviv.franko.triangulation.SaveStructures.Node;
import ua.lviv.franko.triangulation.SaveStructures.Triangle;
import ua.lviv.franko.triangulation.SaveStructures.TriangleL;

/**
 * 
 * @author mark_o
 */
public class jZoneDrawingPanel extends JPanel {

	private static final long	serialVersionUID	= -1868985302780717031L;

	public List<Node>			NodeList;
	public List<Node>			BoundsNodeList;
	public List<Integer>		BoundsNodePosList1;
	public List<Integer>		BoundsNodePosList2;
	public List<Triangle>		TrList;
	public List<Node>			TEMPboundNodes;
	double						coefx;
	double						coefy;
	double						minX;
	double						maxX;
	double						minY;
	double						maxY;

	public List<Integer> getBoundsNodePosList1() {
		return BoundsNodePosList1;
	}

	public List<Integer> getBoundsNodePosList2() {
		return BoundsNodePosList2;
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		SetCoefs();
		drawTriangles(g);
	}

	public void setBoundsNodePosList1(List<Integer> BoundsNodePosList1) {
		this.BoundsNodePosList1 = BoundsNodePosList1;
	}

	public void setBoundsNodePosList2(List<Integer> BoundsNodePosList2) {
		this.BoundsNodePosList2 = BoundsNodePosList2;
	}

	public void SetCoefs() {
		coefy = (double) this.getHeight() / (maxY - minY);
		coefx = (double) this.getWidth() / (maxX - minX);
	}

	public void SetParams(double maxx, double minX, double maxY, double miny) {
		this.maxY = maxY;
		this.maxX = maxx;
		this.minX = minX;
		this.minY = miny;
	}

	protected void drawTriangles(Graphics g) {
		g.setColor(Color.BLACK);
		int n = TrList.size();
		for (int i = 0; i < n; i++) {
			TriangleL tr = (TriangleL) TrList.get(i);
			Node node1 = NodeList.get(tr.A());
			Node node2 = NodeList.get(tr.B());
			Node node3 = NodeList.get(tr.C());

			g.drawLine((int) (coefx * (node1.x - minX)), (int) (coefy * (maxY - node1.y)), (int) (coefx * (node2.x - minX)), (int) (coefy * (maxY - node2.y)));
			g.drawLine((int) (coefx * (node3.x - minX)), (int) (coefy * (maxY - node3.y)), (int) (coefx * (node2.x - minX)), (int) (coefy * (maxY - node2.y)));
			g.drawLine((int) (coefx * (node3.x - minX)), (int) (coefy * (maxY - node3.y)), (int) (coefx * (node1.x - minX)), (int) (coefy * (maxY - node1.y)));
		}
	}

}
